package org.jeecg.modules.userOpenId.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.jeecg.modules.userOpenId.entity.UserOpenId;
import org.jeecg.modules.userOpenId.mapper.UserOpenIdMapper;
import org.jeecg.modules.userOpenId.service.IUserOpenIdService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 用户openId
 * @Author: jeecg-boot
 * @Date:   2025-11-06
 * @Version: V1.0
 */
@Service
public class UserOpenIdServiceImpl extends ServiceImpl<UserOpenIdMapper, UserOpenId> implements IUserOpenIdService {

    @Override
    public UserOpenId getByOpenId(String openId) {
        LambdaQueryWrapper<UserOpenId> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(UserOpenId::getOpenId, openId);
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public UserOpenId getByUserId(String userId) {
        LambdaQueryWrapper<UserOpenId> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(UserOpenId::getUserId, userId);
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public List<String> getOpenIdByRole(String role) {
        LambdaQueryWrapper<UserOpenId> wrapper = Wrappers.lambdaQuery();
        wrapper.like(UserOpenId::getRoleId, role);
        return baseMapper.selectList(wrapper).stream().map(UserOpenId::getOpenId).collect(Collectors.toList());
    }

    @Override
    public String getByUserName(String username) {
        LambdaQueryWrapper<UserOpenId> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(UserOpenId::getUsername, username);
        return baseMapper.selectOne(wrapper).getOpenId();
    }

}
